
#include <light.h>

Light::Light(glm::vec3 *p, glm::vec4 *a, glm::vec4 *d, glm::vec4 *s, char *n) : \
				position(*p),ambient(*a),diffuse(*d),specular(*s),lightId(-1)
{
	strcpy_s(name,n);
}

Light::~Light()
{

}

LightMgr::LightMgr()
{

}

LightMgr::~LightMgr()
{
	int totalLight = lightArray.size();
	for(int i = 0; i < totalLight; i ++)
	{
		delete(lightArray[i]);
	}
}

Light *LightMgr::AddLight(glm::vec3 *position, glm::vec4 *ambient, glm::vec4 *diffuse, glm::vec4 *specular, char *name)
{
	char lightName[0x40] = "Light";
	int totalLight = lightArray.size();
	if(name == 0)
	{
		
		sprintf(lightName,"%s_%d",lightName,totalLight);
	}
	else
	{
		for(int i = 0; i < totalLight; i ++)
		{
			if(!strcmp(name,lightArray[i]->GetName()))
			{
				//already light added...
				return lightArray[i];
			}
		}
		strcpy(lightName,name);
	}
	
	Light *light = new Light(position,ambient,diffuse,specular,lightName);
	if(light != 0)
	{
		lightArray.push_back(light);
	}
	return light;	//null/0 means fail to create light
}

void LightMgr::AddGlobalAmbientLight(glm::vec4 *ambient)
{
	ambientGlobalLight = *ambient;
}

